package com.yanqu.road.logcollector.db;

import com.yanqu.road.logcollector.config.ClickHouseConfig;
import com.yanqu.road.logcollector.config.ConfigBeans;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @Description
 * @Author cwq
 * @Data 2023/5/12 18:20
 */
public class ClickHouseDbMgr {

    private static ClickHouseDbMgr instance = new ClickHouseDbMgr();

    public static ClickHouseDbMgr getInstance() {
        return instance;
    }

    private ClickHousePool clickHousePool;

    public void init() {
        ClickHouseConfig serverConfig = ConfigBeans.getConfigBean(ClickHouseConfig.class);
        clickHousePool = new ClickHousePool(serverConfig);
    }

    public Connection getConnection() throws SQLException {
        if (clickHousePool != null) {
            return clickHousePool.getConnection();
        }
        return null;
    }
}
